Page({

  /**
   * 页面的初始数据
   */
  data: {
    mark: false,
    max: 200,
    min: 0,
    listindex: null,
    imagePath: 'https://mocar.img.xzozo.com/img/icon/home/',
    remarkVal: '',
    jinshidenList: {
      index: 0,
      show: false,
      showList: false,
      arr: [{
          id: 0,
          name: '安全气囊指示灯',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "指示灯不亮",
              "check": '',
            },
            {
              "listId": 1,
              "listName": "指示灯异常闪烁",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "指示灯异常长亮",
              "check": ''
            }
          ]
        },
        {
          id: 1,
          name: '发送机故障指示灯',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "指示灯不亮",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "指示灯异常闪烁",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "指示灯异常长亮",
              "check": ''
            }
          ]
        },
        {
          id: 2,
          name: '电瓶指示灯',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "指示灯不亮",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "指示灯异常闪烁",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "指示灯异常长亮",
              "check": ''
            }
          ]
        },
        {
          id: 3,
          name: '车门状态指示灯',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "指示灯不亮",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "指示灯异常闪烁",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "指示灯异常长亮",
              "check": ''
            }
          ]
        },
        {
          id: 4,
          name: '手刹/驻车指示灯',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "指示灯不亮",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "指示灯异常闪烁",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "指示灯异常长亮",
              "check": ''
            }
          ]
        },
        {
          id: 5,
          name: '机油指示灯',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "指示灯不亮",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "指示灯异常闪烁",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "指示灯异常长亮",
              "check": ''
            }
          ]
        },
        {
          id: 6,
          name: 'ABS指示灯',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "指示灯不亮",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "指示灯异常闪烁",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "指示灯异常长亮",
              "check": ''
            }
          ],
          showList: false
        },
        {
          id: 7,
          name: '其他',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "指示灯不亮",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "指示灯异常闪烁",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "指示灯异常长亮",
              "check": ''
            }
          ]
        }
      ]
    },
    waiguanList: {
      index: 0,
      show: false,
      showList: false,
      arr: [{
          id: 0,
          name: '车身',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "车身有划痕",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "车身凹陷变形",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "车身漆膜脱落",
              "check": ''
            }
          ]
        },
        {
          id: 1,
          name: '玻璃',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "玻璃有划痕、开裂、膨胀",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "车门车窗玻璃松常",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "车窗玻璃升降异常",
              "check": ''
            }
          ]
        },
        {
          id: 2,
          name: '车门',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "车门卡滞、变形",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "车窗玻璃异常",
              "check": ''
            }
          ]
        },
        {
          id: 3,
          name: '雨刷器',
          type: ''
        },
        {
          id: 4,
          name: '后视镜',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "后视镜损坏、异常",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "后视镜连接部分故障",
              "check": ''
            }
          ]
        },
        {
          id: 5,
          name: '保险杠',
          type: ''
        },
        {
          id: 6,
          name: '其他',
          type: ''
        }
      ]
    },
    luntaiList: {
      index: 0,
      show: false,
      showList: false,
      arr: [{
          id: 0,
          name: '左前轮',
          type: '',
          "listItem": [{
              "listId": 0,
              "listName": "胎面磨损",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "胎面老化龟裂鼓包",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "胎压异常",
              "check": ''
            }
          ]
        },
        {
          id: 1,
          name: '左后轮',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "胎面磨损",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "胎面老化龟裂鼓包",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "胎压异常",
              "check": ''
            }
          ]
        },
        {
          id: 2,
          name: '右前轮',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "胎面磨损",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "胎面老化龟裂鼓包",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "胎压异常",
              "check": ''
            }
          ]
        },
        {
          id: 3,
          name: '右后轮',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "胎面磨损",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "胎面老化龟裂鼓包",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "胎压异常",
              "check": ''
            }
          ]
        },
        {
          id: 4,
          name: '备用胎',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "胎面磨损",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "胎面老化龟裂鼓包",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "胎压异常",
              "check": ''
            }
          ]
        }
      ]
    },
    denjuList: {
      index: 0,
      show: false,
      showList: false,
      arr: [{
          id: 0,
          name: '左前灯',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "灯具异常不亮、闪烁、长亮",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "灯具损坏",
              "check": ''
            }
          ]
        },
        {
          id: 1,
          name: '左后灯',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "灯具异常不亮、闪烁、长亮",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "灯具损坏",
              "check": ''
            }
          ]
        },
        {
          id: 2,
          name: '右前灯',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "灯具异常不亮、闪烁、长亮",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "灯具损坏",
              "check": ''
            }
          ]
        },
        {
          id: 3,
          name: '右后灯',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "灯具异常不亮、闪烁、长亮",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "灯具损坏",
              "check": ''
            }
          ]
        },
        {
          id: 4,
          name: '仪表盘',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "灯具异常不亮、闪烁、长亮",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "灯具损坏",
              "check": ''
            }
          ]
        },
        {
          id: 5,
          name: '报警灯',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "灯具异常不亮、闪烁、长亮",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "灯具损坏",
              "check": ''
            }
          ]
        },
        {
          id: 6,
          name: '其他灯',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "灯具异常不亮、闪烁、长亮",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "灯具损坏",
              "check": ''
            }
          ]
        }
      ]
    },
    neibugongnengList: {
      index: 0,
      show: false,
      showList: false,
      arr: [{
          id: 0,
          name: '发动机',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "发动机异响",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "发动机空转、无力、无动作",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "发动机渗油",
              "check": ''
            }
          ]
        },
        {
          id: 1,
          name: '底盘',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "皮带异常",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "底盘磨损、生锈、破损",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "地盘松动",
              "check": ''
            }
          ]
        },
        {
          id: 2,
          name: '制动',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "制动系统失效异常",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "制动拖滞、策划跑偏",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "制动异响",
              "check": ''
            }
          ]
        },
        {
          id: 3,
          name: '空调',
          type: ''
        },
        {
          id: 4,
          name: '转向盘',
          type: '',

          "listItem": [{
              "listId": 0,
              "listName": "转向盘异响",
              "check": ''
            },
            {
              "listId": 1,
              "listName": "转向盘回位困难",
              "check": ''
            },
            {
              "listId": 2,
              "listName": "转向盘跑偏",
              "check": ''
            }
          ]
        },
        {
          id: 5,
          name: '其他',
          type: ''
        }
      ]
    },
    num: 0,
    num1: 0,
    num2: 0,
    num3: 0,
    num4: 0,
    num5: 0,
    date: {
      date: '2019-01-01 13:37',
      startDate: '2019-01-01 12:37',
      endDate: '2019-03-12 12:38',
      placeholder: '请选择时间',
    },
    date1: {
      date: '2019-01-01 13:37',
      startDate: '2019-01-01 12:37',
      endDate: '2019-03-12 12:38',
      placeholder: '请选择时间',
    },
    name: '',
    showModal: false,
    list: [],
    title: '',
    arrList: [],
    tempFilePaths: '', //相册选择相片
    sourceType: '', //相机或者相册
  },
  sellType() {
    var list = ['预检单', '洗车单', '维保单', '销售单'];
    var _this = this
    wx.showActionSheet({
      itemList: list,
      success(res) {
        console.log(list[res.tapIndex])
        _this.setData({
          sellType: list[res.tapIndex],
          colorBool: false
        })
      },
      fail(res) {
        console.log(res.errMsg)
      }
    })
  },
  // 时间选取
  onPickerChange(e) {
    this.setData({
      date: e.detail.dateString
    })
    console.log(this.data.date)
  },
  onPickerChange1(e) {
    this.setData({
      date1: e.detail.dateString
    })
    console.log(this.data.date1)
  },

  // 点击备注
  remarks(e) {
    console.log(e)
    let idx = e.currentTarget.dataset.id //是蓝色部分的id
    this.setData({
      showModal: true,
    })
  },
  //点击备注弹窗的取消按钮
  cancel() {
    this.setData({
      mark: false,
      showModal: false,
    })
  },
  //点击备注弹窗的确定按钮
  determine(e) {
    console.log(e.currentTarget.dataset.hi) //拿到备注框里面的值
  },

  //获取备注弹窗输入的值
  getVal(e) {
    console.log(e.detail.value)
    this.setData({
      remarkVal: e.detail.value
    })
    console.log(this.data.remarkVal)
    if (this.data.remarkVal.length >= 200) {
      wx.showModal({
        title: '提示',
        content: '字数已经上限',
      })
    }
  },
  //警示灯
  showWarn(e) {
    let arr = e.currentTarget.dataset.idx
    let jinshidenList = this.data.jinshidenList
    jinshidenList.show = !jinshidenList.show
    let listItem = this.data.listItem
    this.setData({
      jinshidenList: jinshidenList,
      name: arr[0].name,
    })
  },
  bindcolor(e) {
    const index = e.currentTarget.dataset.index
    let jinshidenList = this.data.jinshidenList;
    jinshidenList.index = index
    let arr = this.data.jinshidenList.arr
    jinshidenList.showList = false
    this.setData({
      jinshidenList: jinshidenList,
      name: arr[index].name,
    })
  },
  //外观
  showAppear(e) {
    let arr = e.currentTarget.dataset.idx
    let waiguanList = this.data.waiguanList
    waiguanList.show = !waiguanList.show
    this.setData({
      waiguanList: waiguanList,
      name: arr[0].name,
      title: 'Appear',
    })
  },
  bindcolor1(e) {
    const index = e.currentTarget.dataset.index
    let waiguanList = this.data.waiguanList;
    waiguanList.index = index
    let arr = this.data.waiguanList.arr
    waiguanList.showList = false
    this.setData({
      waiguanList: waiguanList,
      name: arr[index].name,
    })
  },
  //轮胎
  showTyre(e) {
    let arr = e.currentTarget.dataset.idx
    let luntaiList = this.data.luntaiList
    luntaiList.show = !luntaiList.show
    this.setData({
      luntaiList: luntaiList,
      name: arr[0].name,
    })
  },
  bindcolor2(e) {
    const index = e.currentTarget.dataset.index
    let luntaiList = this.data.luntaiList;
    luntaiList.index = index
    let arr = this.data.luntaiList.arr
    luntaiList.showList = false
    this.setData({
      luntaiList: luntaiList,
      name: arr[index].name,
    })
  },
  //灯具
  showLamp(e) {
    let arr = e.currentTarget.dataset.idx
    let denjuList = this.data.denjuList
    denjuList.show = !denjuList.show
    this.setData({
      denjuList: denjuList,
      name: arr[0].name,
    })
  },
  bindcolor3(e) {
    const index = e.currentTarget.dataset.index
    let denjuList = this.data.denjuList;
    denjuList.index = index
    let arr = this.data.denjuList.arr
    denjuList.showList = false
    this.setData({
      denjuList: denjuList,
      name: arr[index].name,
    })
  },
  //内部功能零件
  showInternal(e) {
    let arr = e.currentTarget.dataset.idx
    let neibugongnengList = this.data.neibugongnengList
    neibugongnengList.show = !neibugongnengList.show
    this.setData({
      neibugongnengList: neibugongnengList,
      name: arr[0].name,
      title: 'inside',
    })
  },
  bindcolor4(e) {
    const index = e.currentTarget.dataset.index
    let neibugongnengList = this.data.neibugongnengList;
    neibugongnengList.index = index
    let arr = this.data.neibugongnengList.arr
    neibugongnengList.showList = false
    this.setData({
      neibugongnengList: neibugongnengList,
      name: arr[index].name,
    })
  },

  // 车主备注
  inputs: function (e) {
    var value = e.detail.value;
    var len = parseInt(value.length);
    if (len > this.data.max) return;

    this.setData({
      currentWordNumber: len
    });
    if (this.data.currentWordNumber == 200) {
      wx.showModal({
        title: '提示',
        content: '您输入的次数已达上限',
      })
    }
  },

  // 点击单选框
  dianWarn(e) {
    let id = e.currentTarget.dataset.id;
    let jinshidenList = this.data.jinshidenList;
    jinshidenList.arr[jinshidenList.index].type = id
    if (id == 0) {
      jinshidenList.showList = false
    } else {
      jinshidenList.showList = true
    }
    let arr = jinshidenList.arr
    this.setData({
      jinshidenList: jinshidenList,
    })
  },


  dianAppear(e) {
    let id = e.currentTarget.dataset.id;
    let waiguanList = this.data.waiguanList;
    waiguanList.arr[waiguanList.index].type = id
    if (id == 0) {
      waiguanList.showList = false
    } else {
      waiguanList.showList = true
    }
    this.setData({
      waiguanList: waiguanList,
    })
  },

  dianTyre(e) {
    let id = e.currentTarget.dataset.id;
    let luntaiList = this.data.luntaiList;
    luntaiList.arr[luntaiList.index].type = id
    if (id == 0) {
      luntaiList.showList = false
    } else {
      luntaiList.showList = true
    }
    this.setData({
      luntaiList: luntaiList
    })
  },

  dianLamp(e) {
    let id = e.currentTarget.dataset.id;
    let denjuList = this.data.denjuList;
    denjuList.arr[denjuList.index].type = id
    if (id == 0) {
      denjuList.showList = false
    } else {
      denjuList.showList = true
    }
    this.setData({
      denjuList: denjuList
    })
  },

  dianInternal(e) {
    let id = e.currentTarget.dataset.id;
    let neibugongnengList = this.data.neibugongnengList;
    neibugongnengList.arr[neibugongnengList.index].type = id
    if (id == 0) {
      neibugongnengList.showList = false
    } else {
      neibugongnengList.showList = true
    }
    this.setData({
      neibugongnengList: neibugongnengList,
    })
  },

  // 调用相机
  chooseImage() {
    var _this = this
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: this.data.sourceType,
      success(res) {
        _this.setData({
          tempFilePaths: res.tempFilePaths
        })
      }
    })
  },
  // 上传图片
  upload() {
    var _this = this
    wx.showActionSheet({
      itemList: ['选择相机', '从手机相册选择'],
      success(res) {
        if (res.tapIndex == 0) {
          _this.setData({
            sourceType: ['camera']
          })
          _this.chooseImage()
        }
        if (res.tapIndex == 1) {
          _this.setData({
            sourceType: ['album']
          })
          _this.chooseImage()
        }
      },
      fail(res) {
        console.log(res.errMsg)
      }
    })
  },
  //清除图片
  clear() {
    this.setData({
      tempFilePaths: ''
    })
  },

  //展示异常的数据
  showExcept(e) {
    let title = e.currentTarget.dataset.title
    console.log(e)
    if (title == 'warn') {
      var list = this.data.jinshidenList
    } else if (title == 'appear') {
      var list = this.data.waiguanList
    } else if (title == 'tyre') {
      var list = this.data.luntaiList
    } else if (title == 'lamp') {
      var list = this.data.denjuList
    } else if (title == 'internal') {
      var list = this.data.neibugongnengList
    }
    let arr = list.arr
    let str = e.currentTarget.dataset.id
    let strId = str.listId
    let idx = e.currentTarget.dataset.hi
    let listItem = arr[idx].listItem
    console.log(str)
    let strArr = []
    if (listItem[strId].check == '') {
      listItem[strId].check = true
      strArr.push(str)
    } else {
      listItem[strId].check = false
      strArr.splice(strId, 1)
    }
    this.setData({
      jinshidenList: list
    })
    console.log(strArr)
  }

})